//import javax.swing.*;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//
//public class Login extends JFrame {
//    Login father = this;
//    JTextField user = null;
//    JPasswordField password = null;
//    JButton button1 = null;
//    String flag = "teacher";
//    Login() {
//        this.setSize(500, 420);
//        this.setLocationRelativeTo(null);
//        this.setTitle("学生成绩管理系统");
//        this.setResizable(false);
//        init();
//        this.setVisible(true);
//        password.requestFocus();//让密码输入框获得焦点
//    }
//    public void login() {//进入主菜单事件
//        String password_true = null; String where = " where T_ID = "; if (flag.equals("teacher")) {
//        where = " where T_ID = ";
//    } else {
//        where = " where S_ID = ";
//    }
//    try {
//        String password_sql = "select passcode from ssms." + flag + where + Integer.parseInt(user.getText()) + ";";
//        Connection conn = Main.sendConnection();
//        PreparedStatement stmt =
//                conn.prepareStatement(password_sql);
//        ResultSet result = stmt.executeQuery();
//        result.next();
//        password_true = result.getString("passcode");
//    } catch (SQLException e) {
//        e.printStackTrace();
//
//    }
//    char[] pswd = password.getPassword();
//if (String.valueOf(pswd).equals(password_true)) {//密码JOptionPane.showMessageDialog(father, "登陆成功！"); if (flag.equals("teacher")) {
//        TeacherMenu teacherMenu = new TeacherMenu();//创建主菜
//        teacherMenu.sendObject(father);//传递主窗口引用teacherMenu.sendID(user.getText());//传递输入的账号ID 用于数据库的操作等
//        teacherMenu.init();
//    } else {
//        StudentMenu studentMenu = new StudentMenu();
//        studentMenu.sendObject(father);
//        studentMenu.sendID(user.getText());
//        studentMenu.init();
//    }
//father.setVisible(false);//进入主菜单界面时隐藏登录界面
//} else {
//        JOptionPane.showMessageDialog(father, "账号或密码错误！", " 错误", JOptionPane.WARNING_MESSAGE);
//}
//        }
//public void init() {
//    setLayout(new GridLayout(2, 1, 0, 0));
//    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//    JPanel panel1 = new JPanel() {//登录界面上半部分private static final long serialVersionUID = 1L;
//        ImageIcon image = new ImageIcon("Image\\up.png");//登录界面上部图片
//        public void paintComponent(Graphics g) {
//            super.paintComponent(g);
//            g.drawImage(image.getImage(), 0, 0, this.getWidth(),
//                    this.getHeight(), this);
//        }
//    };
//    panel1.setLayout(null);
//    JPanel head = new JPanel() {//头像
//        private static final long serialVersionUID = 1L;
//        ImageIcon icon = new ImageIcon("Image\\flower.jpg");
//        public void paintComponent(Graphics g) {
//            super.paintComponent(g);
//            g.drawImage(icon.getImage(), 0, 0, this.getWidth(),
//                    this.getHeight(), this);
//        }
//    };
//    head.setBounds(200, 70, 100, 100);
//    panel1.add(head);
//    JPanel panel2 = new JPanel(new GridLayout(2, 1, 0, 0));//登录界面下半部分
//    add(panel1);
//    add(panel2);
//    JLabel label1 = new JLabel("账	号：");
//    JLabel label2 = new JLabel("密	码：");
//    user = new JTextField("10001", 15);//账号输入框password = new JPasswordField(15);//密码输入框
//    password.addActionListener(e -> login());//密码框添加回车登录事件，进入主菜单界面
//    JPanel panel3 = new JPanel(new GridLayout(2, 1, 0, 0));//放置用户名和密码及其输入框
//    JPanel panel4 = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 16));//放置用户名及其输入框
//    JPanel panel5 = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 16));//放置密码及其输入框
//    panel3.add(panel4);
//    panel3.add(panel5);
//    panel4.add(label1);
//    panel4.add(user);//添加用户名输入框panel5.add(label2); panel5.add(password);//添加密码输入框panel2.add(panel3);
//    button1 = new JButton("登	录");
//    JButton button2 = new JButton("退	出");
//    button1.setFocusPainted(false);//不绘制焦点button2.setFocusPainted(false);
//    try {//改变成 win10风格UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
//             | UnsupportedLookAndFeelException e) {
//        e.printStackTrace();
//    }
//    button1.addActionListener(e -> login());
//    button2.addActionListener(e -> System.exit(0));//lambda 表达式JPanel panel_choice = new JPanel();
//    JRadioButton radioButton_1 = new JRadioButton("教师", true);// 默认选择教师登录
//    JRadioButton radioButton_2 = new JRadioButton("学生");
//    radioButton_1.setFocusPainted(false);
//    radioButton_2.setFocusPainted(false);
//    radioButton_1.addActionListener(e -> flag = "teacher");
//    radioButton_2.addActionListener(e -> flag = "student");
//    ButtonGroup group = new ButtonGroup();
//    group.add(radioButton_1);
//    group.add(radioButton_2);
//    panel_choice.add(radioButton_1);
//    panel_choice.add(radioButton_2);
//    JPanel panel6 = new JPanel(new GridLayout(3, 1, 0, 0));
//    panel2.add(panel6);
//    panel6.add(panel_choice);
//    JPanel panel_button = new JPanel(new FlowLayout(FlowLayout.CENTER, 30, 5));
//    panel_button.add(button1);
//    panel_button.add(button2);
//    panel6.add(panel_button);
//    panel6.add(new JPanel());
//}
//}
//
//public class Main {
//    static Connection sendConnection() {
//        String driver = "com.mysql.cj.jdbc.Driver";
////URL 指向要访问的数据库名String url =
//        "jdbc:mysql://localhost:3306/world?serverTimezone=UTC";
////MySQL 配置时的用户名String user = "root";
////MySQL 配置时的密码
//        String password = "n3483226";
//        Connection conn = null;
//        try {
//            Class.forName(driver);
//            conn = DriverManager.getConnection(url, user, password);
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return conn;
//    }
//    public static void main(String[] args) {
//        new Login();
//    }
//}
//
//
//class ReturnQueryResult {
//    public static String[][] send(String sql) {
//        String[][] result = null;
//        Connection conn = null;
//        Statement statement = null;
//        try {
//            conn = Main.sendConnection();
//            statement = conn.createStatement();
//            ResultSet rs = statement.executeQuery(sql);
//            ResultSetMetaData rsmd = rs.getMetaData();
//            int column = rsmd.getColumnCount();//获取列数rs.last();
//            int row = rs.getRow();//获取行数rs.beforeFirst();
//            result = new String[row][column];
//            int count = 0;
//            while (rs.next()) {
//                for (int i = 1; i <= column; i++) {
//                    result[count][i - 1] = rs.getString(i);
//                }
//                count++;
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return result;
//    }
//}
//
//public class TeacherMenu extends JFrame {
//    TeacherMenu father = this;
//    Login send = null;
//    JPanelRight flag = null;
//    String input_ID = null;
//    JPanel panel_top = null;
//    JPanelLeft panel_left = null;
//    JPanelRight panel_right = null;
//    JPanelLeft showmessage = null;
//    static final CardLayout cl = new CardLayout();
//    public TeacherMenu() {
//        this.setLayout(new GridBagLayout());//主菜单界面为网格包布局管理器
//
//    }
//this.setSize(1200, 800);
//this.setLocationRelativeTo(null);
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
////获取登录界面对象的引用void sendObject(Login o) {
//    send = o;
//}
////获取登录时用户输入的账号void sendID(String ID) {
//input_ID = ID;
//}
//public void init() {//在主菜单界面添加 panel panel_top = new JPanel();
//    JLabel label_title = new JLabel("欢迎使用学生成绩管理系统");
//    ;
//    label_title.setFont(new Font("宋体", Font.ROMAN_BASELINE, panel_top.add(label_title);
//    panel_top.setBackground(new Color(0xAFEEEE)); this.add(panel_top, new MyGridBagConstraints(0, 0, 2, 1).
//            setFill(GridBagConstraints.BOTH).setIpad(200, 50).setWeight(100, 0));
//    panel_right = new JPanelRight();
//    this.add(panel_right, new MyGridBagConstraints(1, 1, 1, 1).setFill(GridBagConstraints.BOTH));
//    panel_left = new JPanelLeft();
//    this.add(panel_left, new MyGridBagConstraints(0, 1, 1, 1). setFill(GridBagConstraints.BOTH).setWeight(0,
//            setIpad(100, 300));
//    this.setVisible(true);
//}
//class JPanelLeft extends JPanel {//放置左侧按钮面板JPanelLeft dad = this;
//    public JPanelLeft() {
//        showmessage = this;
//        this.setLayout(new GridBagLayout());
//        init();
//    }
//    JPanel panel_head = new JPanel();
//    JPanel panel_tail = new JPanel();
//    JButton button_search = new JButton("主页");
//    JButton button_add = new JButton("添加");
//    JButton button_score = new JButton("成绩统计");
//    JButton button_message = new JButton("个人信息");
//    JButton button_quit = new JButton("退出系统");
//    void init() {
//        button_search.addActionListener(e -> cl.show(panel_right,
//                "home"));
//        "insert"
//                                             ));
//        button_add.addActionListener(e -> cl.show(panel_right, button_score.addActionListener(e -> {
//            flag.init();
//            cl.show(panel_right, "score");
//        }); button_message.addActionListener(e -> cl.show(panel_right,
//                "message"));
//        add(panel_head, new MyGridBagConstraints(0, 0, 1,
//                setInset(new Insets(5, 0, 5, 0)).
//                        setFill(GridBagConstraints.BOTH).setWeight(10,
//                                setIpad(1, 1));
//        add(button_search, new MyGridBagConstraints(0, 2, 1,
//                setInset(new Insets(5, 0, 5, 0)).
//                        setFill(GridBagConstraints.BOTH).setIpad(20,
//        ;
//        add(button_add, new MyGridBagConstraints(0, 3, 1,
//                setInset(new Insets(5, 0, 5, 0)).
//                        setFill(GridBagConstraints.BOTH).setIpad(20,
//        ;
//        add(button_score, new MyGridBagConstraints(0, 4, 1,
//                setInset(new Insets(5, 0, 5, 0)).
//                        setFill(GridBagConstraints.BOTH).setIpad(20,
//        ;
//        add(button_message, new MyGridBagConstraints(0, 6, 1,
//                setInset(new Insets(5, 0, 5, 0)).
//                        setFill(GridBagConstraints.BOTH).setIpad(20,
//        ;
//        add(panel_tail, new MyGridBagConstraints(0, 7, 1,
//                setInset(new Insets(5, 0, 5, 0)).
//                        setFill(GridBagConstraints.BOTH).setWeight(10,
//                                setIpad(1, 1));
//    }
//}
//class JPanelRight extends JPanel {//放置右侧 主页面板，个人信息面板等
//    JPanelRight parent = this;
//    public JPanelRight() {
//        flag = this;
//        this.setBackground(Color.MAGENTA);
//        this.setLayout(cl);//CardLayout init();
//    }
//    void init() {
//        JPanelHome panel_home = new JPanelHome();
//        JPanelInsert panel_insert = new JPanelInsert();
//        JPanelScore panel_score = new JPanelScore();
//        PanelMessage panel_message = new PanelMessage();
//        add(panel_home, "home");
//        add(panel_insert, "insert");
//        add(panel_score, "score");
//        add(panel_message, "message");
//    }
//    //添加学生信息面板类
//    class JPanelInsert extends JPanelHome {
//        JPanelInsert() {
//            this.setLayout(new GridLayout(7, 2));
//        }
//        void init() {
//            JPanel[] panels = new JPanel[7];
//            for (int i = 0; i < panels.length; i++) {
//                panels[i] = new JPanel();
//                "电话"
//            };
//        }
//        JLabel title = new JLabel("添加学生信息：");
//        panels[0].setLayout(new FlowLayout(FlowLayout.LEFT));
//        panels[0].add(title);
//        JLabel[] jLabels = new JLabel[5];
//        JTextField[] jTextFields = new JTextField[5];
//        String[] label_text = {"学号", "姓名", "性别", "年龄",
//        for (int i = 0; i < 5; i++) {
//            jLabels[i] = new JLabel(label_text[i]);
//            jTextFields[i] = new JTextField(20);
//            panels[i + 1].add(jLabels[i]);
//            panels[i + 1].add(jTextFields[i]);
//            ;
//        }
//        JButton button_confirm = new JButton("添加");
//        button_confirm.setPreferredSize(new Dimension(100,
//                                                      button_confirm.addActionListener(e -> { Connection conn = Main.sendConnection(); try {
//            String sql_student = "insert into ssms.student
//            values (" + jTextFields[0].getText() + ", '"
//                    + jTextFields[1].getText() + "', '" +
//                    jTextFields[2].getText() + "', "
//                    + jTextFields[3].getText() + ", '" + jTextFields[4].getText() + "', '123456'); ";
//            PreparedStatement pstmt = conn.prepareStatement(sql_student);
//            pstmt.executeUpdate();
//            for (int i = 1; i <= 4; i++) {//在 score 表添加默认成绩 0 分
//                String sql_score = "insert into ssms.score
//                values(" + jTextFields[0].getText() + ", 1000" + i + ", 0); ";
//                pstmt = conn.prepareStatement(sql_score);
//                pstmt.executeUpdate();
//            }
//            JOptionPane.showMessageDialog(this, "添加成功！
//                    ",
//                    "Succeed",
//                    JOptionPane.INFORMATION_MESSAGE);
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            JOptionPane.showMessageDialog(this, "格式有误，请重新输入！";
//            JOptionPane.WARNING_MESSAGE);
//        }
//            "Error",
//        });
//        panels[6].add(button_confirm);
//for (int i = 0; i < panels.length; i++) {
//            this.add(panels[i]);
//        }
//    }
//}
////统计学生信息面板类
//class JPanelScore extends JPanelHome {
//    JPanelShow panel_show = new JPanelShow();
//    CardLayout layout = (CardLayout)panel_show.getLayout();
//    JPanelScore() {
//        this.setLayout(new BorderLayout());
////	this.removeAll();
//        JLabel title = new JLabel("成绩统计:");
//        title.setFont(new Font("楷体", Font.BOLD, 30));
//        this.add(title,BorderLayout.NORTH);
//        this.add(panel_show, BorderLayout.CENTER);
//        JPanelButton panel_button = new JPanelButton();
//        panel_button.setPreferredSize(new Dimension(0, 100));
//        this.add(panel_button,BorderLayout.SOUTH);
//    }
//    , 40));
//    class JPanelButton extends JPanel {
//        JPanelButton() {
//            this.setLayout(new FlowLayout(FlowLayout.CENTER,
//                    String[] button = {"总成绩", "Java", "数据库原理",
//                    "算法与数据结构", "C++"
//            };
//            JButton[] button_all = new JButton[5]; for(int i=0; i<button.length; i++) {
//                button_all[i] = new JButton(button[i]);
//                this.add(button_all[i]);
//            }
//            button_all[0].addActionListener(e->layout.show(panel_show, "0"));
//            button_all[1].addActionListener(e->layout.show(panel_show, "1"));
//            button_all[2].addActionListener(e->layout.show(panel_show, "2"));
//            button_all[3].addActionListener(e->layout.show(panel_show, "3"));
//            button_all[4].addActionListener(e->layout.show(panel_show, "4"));
//        }
//    }
//    class JPanelShow extends JPanel {
//        JPanel[] panels = new JPanel[5];
//        JPanelShow() {
//            this.setLayout(new CardLayout());
//            for(int i=0; i<panels.length; i++) {
//                panels[i] = new JPanel(new BorderLayout());
//                this.add(panels[i], i + "");
//            }
//            show_all();
//            show_single(1, "10001");
//            show_single(2, "10002");
//            show_single(3, "10003");
//            show_single(4, "10004");
//        }
//        void show_single(int no, String t_no) {
//            String[] head = {"学号", "姓名", "成绩", "排名"};
//            String sql = "select r.*, row_number() over(order by 'subject') as row_rank\n" +
//                    score.T_ID = " + t_no +
//            "from(\n" +
//                    "select score.S_ID, student.name,\n" + "sum(score.grade) as 'subject'\n" + "from ssms.score, ssms.student\n" + "where score.S_ID = student.S_ID and
//            " group by score.S_ID\n" + "order by score.grade desc) r";
//            String[][]	result = ReturnQueryResult.send(sql);
//            MyTable table = new MyTable(result, head);
//            JScrollPane jsp = new JScrollPane(table);
//            panels[no].add(jsp, BorderLayout.CENTER);
//            String[] head_1 = {"分数段", "优秀(90~100)", "良好(80~90)", "中等(70~80)","及格(60~70)", "不及格(0~60)"};
//            String[][] result_1 = new String[1][6];
//            result_1[0][0] = "人数";
//            String sql_1 = "select count(case when
//